package cn.jsoup;

import cn.wanghaomiao.xpath.exception.XpathSyntaxErrorException;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.File;
import java.io.IOException;

public class jsoupDemo6 {
    public static void main(String[] args) throws IOException, XpathSyntaxErrorException {
        String path = jsoupDemo6.class.getClassLoader().getResource("student.xml").getPath();
        //获取html路径
        Document document = Jsoup.parse(new File(path), "UTF-8");
        //将html文件进行解析
        Elements students = document.getElementsByTag("student");
        //获取元素对象也就是标签对象通过getElementBytag方法
        for (Element student : students) {//遍历获取的数组
            Elements names = student.getElementsByTag("name");
//            System.out.println(names);
//            System.out.println("---------------");
        }
        Elements numbers = document.getElementsByAttribute("number");
        //通过标签的属性获取标签对象
         document.getElementsByAttributeValue("number","itcast_0001");
         //通过标签的属性和值获取标签对象
        Element heima = document.getElementById("heima");
        //通过id获取标签对象
        System.out.println(heima);


    }
}
